package cn.ekgc.bmdsad.day2;

public class MyTreeSet {
    private MyNode root;
    class MyNode{
        private int data;
        private MyNode left;
        private MyNode right;

        public void add(MyNode node) {
            if(this.data > node.data){
                if(this.left == null){
                    this.left = node;
                }else {
                    this.left.add(node);
                }
            }
            if(this.data < node.data){
                if(this.right == null ){
                    this.right = node;
                }else {
                    this.right.add(node);
                }
            }
        }

        public void zhongxu() {
            if(this.left!=null){
                this.left.zhongxu();
            }
            System.out.println(this.data);
            if(this.right!=null){
                this.right.zhongxu();
            }
        }
    }
    public void add(int i) {
        MyNode  node = new MyNode();
        node.data = i;
        if(root == null){
            root = node;
        }else{
            root.add(node);
        }
    }

    public void zhongxu() {
        this.root.zhongxu();
    }
}

